package com.ruoyi.service.impl;
import com.ruoyi.domain.BrandInfo;
import com.ruoyi.mapper.BrandInfoMapper;
import com.ruoyi.mapper.CategoryBrandMapper;
import com.ruoyi.service.IBrandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class BrandInfoServiceImpl implements IBrandInfoService {
    @Autowired
    BrandInfoMapper brandInfoMapper;

    @Autowired
    CategoryBrandMapper categoryBrandMapper;

    @Override
    public List<BrandInfo> list() {
        return brandInfoMapper.selectList();
    }

    @Override
    public List<BrandInfo> listByConeAll() {
        List<BrandInfo> brandInfos = brandInfoMapper.selectListAll();
        for (BrandInfo brandInfo : brandInfos){
            System.out.println("brandInfo.getConeIdsStr() = " + brandInfo.getConeIdsStr());
            // 从对象中 取 id
//            List<Integer> coneIds =categoryBrandMapper.selectConeIdByBrandInfo(brandInfo.getBrandId());
//            System.out.println("coneIds = " + coneIds);
            List<Integer> coneIds = new ArrayList<>();;
            if (brandInfo.getConeIdsStr() != null){
            String[] ss = brandInfo.getConeIdsStr().split(",");
                int[] array = Arrays.stream(ss).mapToInt(Integer::parseInt).toArray();

                for (String s:ss){
                    coneIds.add(Integer.parseInt(s));
                }
            }

            // 给id 的 list set到 conids
            brandInfo.setConeIds(coneIds);
        }
        return brandInfos;
    }

    @Override
    public List<BrandInfo> selectByBrandInfoListAll() {
        return null;
    }

    @Override
    public List<BrandInfo> listForPage(BrandInfo brandInfo) {
        return brandInfoMapper.selectListForPage(brandInfo);
    }

    @Override
    public BrandInfo getById(Long id) {
        return brandInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int save(BrandInfo brandInfo) {
        return brandInfoMapper.insertSelective(brandInfo);
    }

    @Override
    public int updateById(BrandInfo brandInfo) {
        return brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
    }

    @Override
    public List<BrandInfo> listByCone(Long id) {
        return brandInfoMapper.selectListByCone(id);
    }


    @Override
    public int removeByIds(Long[] ids) {
        return brandInfoMapper.delectByPrimaryKeys(ids);
    }
}
